/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/idenger">idenger</a> All rights reserved.
 */
package com.idenger.modules.edu.web.course;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.idenger.common.config.Global;
import com.idenger.common.persistence.Page;
import com.idenger.common.web.BaseController;
import com.idenger.common.utils.StringUtils;
import com.idenger.modules.edu.entity.course.EduCourseTeacher;
import com.idenger.modules.edu.service.course.EduCourseTeacherService;

/**
 * 课程教师Controller
 * @author chenlin
 * @version 2017-11-30
 */
@Controller
@RequestMapping(value = "${adminPath}/edu/course/eduCourseTeacher")
public class EduCourseTeacherController extends BaseController {

	@Autowired
	private EduCourseTeacherService eduCourseTeacherService;
	
	@ModelAttribute
	public EduCourseTeacher get(@RequestParam(required=false) String id) {
		EduCourseTeacher entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = eduCourseTeacherService.get(id);
		}
		if (entity == null){
			entity = new EduCourseTeacher();
		}
		return entity;
	}
	
	@RequiresPermissions("edu:course:eduCourseTeacher:view")
	@RequestMapping(value = {"list", ""})
	public String list(EduCourseTeacher eduCourseTeacher, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EduCourseTeacher> page = eduCourseTeacherService.findPage(new Page<EduCourseTeacher>(request, response), eduCourseTeacher); 
		model.addAttribute("page", page);
		return "modules/edu/course/eduCourseTeacherList";
	}

	@RequiresPermissions("edu:course:eduCourseTeacher:view")
	@RequestMapping(value = "form")
	public String form(EduCourseTeacher eduCourseTeacher, Model model) {
		model.addAttribute("eduCourseTeacher", eduCourseTeacher);
		return "modules/edu/course/eduCourseTeacherForm";
	}

	@RequiresPermissions("edu:course:eduCourseTeacher:edit")
	@RequestMapping(value = "save")
	public String save(EduCourseTeacher eduCourseTeacher, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, eduCourseTeacher)){
			return form(eduCourseTeacher, model);
		}
		eduCourseTeacherService.save(eduCourseTeacher);
		addMessage(redirectAttributes, "保存课程教师成功");
		return "redirect:"+Global.getAdminPath()+"/edu/course/eduCourseTeacher/?repage";
	}
	
	@RequiresPermissions("edu:course:eduCourseTeacher:edit")
	@RequestMapping(value = "delete")
	public String delete(EduCourseTeacher eduCourseTeacher, RedirectAttributes redirectAttributes) {
		eduCourseTeacherService.delete(eduCourseTeacher);
		addMessage(redirectAttributes, "删除课程教师成功");
		return "redirect:"+Global.getAdminPath()+"/edu/course/eduCourseTeacher/?repage";
	}

}